package com.bonc.rms.controller.tms;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.bonc.rms.service.tms.EmployeeDimissionService;

@Controller
@RequestMapping(value = "/employeeDimissionController")

public class EmployeeDimissionController {

	@Autowired
    private EmployeeDimissionService employeeMissionService; 
    
    /**
     * 短期离职员工预警
     * 
     * @param departmentId
     * @param
     * @return
     */
    @RequestMapping(value = "/shortDimissionEmployee")
    @ResponseBody
    public String getShortDimissionEmployee(
    		@RequestParam(value = "departmentId") Integer departmentId, 
    		@RequestParam(value = "pageNum") Integer pageNum
    		) {

    	if(pageNum == null || pageNum < 0) {
    		pageNum = 0;
    	}
    	int pageSize = 10;
    	int totalNumber = employeeMissionService.getTotalNumber(departmentId);
    	int totalPage = totalNumber % pageSize == 0 ? totalNumber / pageSize : (totalNumber / pageSize) + 1;
    	
        Map<String, Object> retMap = new HashMap<String, Object>();
        retMap.put("data", employeeMissionService.getShortDimissionEmployee(departmentId, pageNum, pageSize));
        retMap.put("totalNumber", totalNumber);
        retMap.put("prePage", pageNum - 1);
        retMap.put("curPage", pageNum);
        retMap.put("nextPage", pageNum + 1);
        retMap.put("firstPage", 0);
        retMap.put("lastPage", totalPage - 1);
        retMap.put("totalPage", totalPage);
        retMap.put("pageSize", pageSize);
        
        return JSON.toJSONString(retMap);
    }
    
    /**
     * 部门薪资总览
     * 
     * @param departmentId
     * @param
     * @return
     */
    @RequestMapping(value = "/departmentWages", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String getDepartmentWages(
    		@RequestParam(value = "departmentId") Integer departmentId, 
    		@RequestParam(value = "startTime") String startDate, 
    		@RequestParam(value = "endTime") String endDate, 
    		@RequestParam(value = "pageNum") Integer pageNum, 
    		@RequestParam(value = "mycars[]")String[] mycars, 
    		HttpSession httpSession
    		) {
  	
        if( null == startDate || "".equals(startDate) || null == endDate || "".equals(endDate)) {
            String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
            startDate = year + "-01";
            endDate = year + "-12";
        }
       
       
        
        int pageSize = 10;
    	int totalNumber = employeeMissionService.getTotalDepNumber(departmentId);
    	int totalPage = totalNumber % pageSize == 0 ? totalNumber / pageSize : (totalNumber / pageSize) + 1;
    	
        Map<String, Object> retMap = new HashMap<String, Object>();
        retMap.put("data", employeeMissionService.getDepartmentWages(-1, departmentId, startDate, endDate, pageNum, pageSize));
        retMap.put("totalNumber", totalNumber);
        retMap.put("prePage", pageNum - 1);
        retMap.put("curPage", pageNum);
        retMap.put("nextPage", pageNum + 1);
        retMap.put("firstPage", 0);
        retMap.put("lastPage", totalPage - 1);
        retMap.put("totalPage", totalPage);
        retMap.put("pageSize", pageSize);
        System.out.println("mycarsmycarsmycarsmycarsmycars"+mycars[1]);
        return JSON.toJSONString(retMap);
    }
    
}
